namespace SimpleWebServices.Models
{
    using System.Xml.XPath;
    using SimpleWebServices;
    using Xunit;

    public sealed class FaviconFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<Favicon>()
                .DerivesFrom<object>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .XmlRoot("favicon")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            Favicon actual = "<favicon rel='icon' type='image/x-icon' href='http://static.example.com/-/favicon.ico' />".Deserialize<Favicon>();

            Assert.Equal<string>("http://static.example.com/-/favicon.ico", actual.Href);
            Assert.Equal<string>("icon", actual.Relationship);
            Assert.Equal<string>("image/x-icon", actual.Type);
        }

        [Fact]
        public void deserializeEmpty()
        {
            Favicon actual = "<favicon />".Deserialize<Favicon>();

            Assert.Null(actual.Href);
            Assert.Null(actual.Relationship);
            Assert.Null(actual.Type);
        }

        [Fact]
        public void serialize()
        {
            Favicon obj = new Favicon
            {
                Href = "http://static.example.com/-/favicon.ico",
                Relationship = "icon",
                Type = "image/x-icon"
            };

            XPathNavigator navigator = obj.Serialize().CreateNavigator();

            Assert.True((bool)navigator.Evaluate("1=count(/favicon[@rel='icon'][@type='image/x-icon'][@href='http://static.example.com/-/favicon.ico'])"));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new Favicon());
        }

        [Fact]
        public void prop_Href()
        {
            Assert.True(new PropertyExpectations(typeof(Favicon).GetProperty("Href"))
                .XmlAttribute("href")
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_Relationship()
        {
            Assert.True(new PropertyExpectations(typeof(Favicon).GetProperty("Relationship"))
                .XmlAttribute("rel")
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_Type()
        {
            Assert.True(new PropertyExpectations(typeof(Favicon).GetProperty("Type"))
                .XmlAttribute("type")
                .IsAutoProperty<string>()
                .Result);
        }
    }
}